from typing import List


class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
        index = 0
        res = ""
        while(len(strs) > 0):
            c = ""
            for i in range(0, len(strs)):
                if(len(strs[i]) <= index):
                    return res
                c1 = strs[i][index]
                if(i == 0):
                    c = c1
                elif(c != c1):
                    return res
            index = index+1
            res = res+c
        return res


if __name__ == "__main__":
    print(Solution().longestCommonPrefix(["flower", "flow", "flight"]))
    print(Solution().longestCommonPrefix(["dog", "racecar", "car"]))
    print(Solution().longestCommonPrefix([""]))
    print(Solution().longestCommonPrefix([]))
    print(Solution().longestCommonPrefix(["a"]))
